﻿// ===================================
// The use and distribution terms for this software are covered by the Microsoft public license, 
// visit for more info : http://testcommander.codeplex.com 
// 
// You must not remove this copyright notice, or any other, from this software
// 
// Senthil Maruthaiappan  senips@gmail.com
// ===================================

using System.Text;
using QAPro.Test.FitServices.Interfaces;
using QAPro.Test.Interfaces;
using QAPro.Test.Library;
using WiseLight.Framework.Lite.Container;

namespace QAPro.Test.Addin.Fitnesse
{
    [InstanceBehaviour(typeof (IFixtureTable), InstanceBehaviourType.AlwaysCreate)]
    public class FitFixtureTable : FixtureTable, IFitRunnableDoc, IFitResultDoc
    {
        private IFitUtilService _fitUtilService;

        public FitFixtureTable(string name) : base(name)
        {
        }

        private IFitUtilService FitUtilityService
        {
            get
            {
                if (_fitUtilService == null)
                    _fitUtilService = Services.Get<IFitUtilService>();
                return _fitUtilService;
            }
        }

        #region IFitResultDoc Members

        public string GetResultDocument()
        {
            return (TestResult as IFitResult) != null ? (TestResult as IFitResult).ResultText : string.Empty;
        }

        #endregion

        #region IFitRunnableDoc Members

        public string GetTestDocument()
        {
            var result = new StringBuilder();
            result.AppendLine("ID={" + ID + "}");
            FitUtilityService.GetAsHtmlTable(FixtureData, ref result);
            return result.ToString();
        }

        #endregion
    }
}